﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Threading;

namespace CentrisScraper.Lib.Emails
{
    /// <summary>
    /// Smtp email sender
    /// </summary>
    public class SmtpEmailSender
    {
        public void Send(Email email)
        {
            // create mail message object
            var mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("admin@centrisscraper.zapto.org");
            mailMessage.To.Add(email.To);
            if (email.Cc != null)
                mailMessage.CC.Add(email.Cc);
            if (email.Bcc != null)
                mailMessage.Bcc.Add(email.Bcc);
            mailMessage.Subject = email.Subject;
            mailMessage.Body = email.Body;
            mailMessage.Body = mailMessage.Body;
            mailMessage.IsBodyHtml = true;

            // we add the attachments
            foreach (string filePath in email.Attachments)
            {
                mailMessage.Attachments.Add(new Attachment(filePath));
            }

            // we setup the smtp client
            var smtpClient = new SmtpClient("localhost", 25);
            smtpClient.Send(mailMessage);
        }
    }
}
